home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / windows / pcpwhost.zip / HOST1C.COM / MAIL.WAS < prev    next >
Text File  |  1992-09-01  |  20KB  |  635 lines

  1. ; Host Mode Mail v1.00c file - Do not compile!
  2.  
  3. ;***********************************************************************
  4. ;*                                                                     *   
  5. ;* MAIL.WAS                                                            *
  6. ;* Copyright (C) 1992 Datastorm Technologies, Inc.                     *     
  7. ;* All rights reserverd.                                               * 
  8. ;*                                                                     * 
  9. ;* Purpose: Contains the Host Mail routines for Host Mode              *
  10. ;*                                                                     * 
  11. ;***********************************************************************
  12.  
  13. ;***********************************************************************
  14. ;*                                                                     *
  15. ;*  WARNING!!!!                                                        *
  16. ;*                                                                     *
  17. ;*  Do not modify this script file unless you have a good under-       *
  18. ;*  standing of the Windows ASPECT language.  If you do modify this    *
  19. ;*  script, PLEASE MAKE A BACKUP before doing so.                      *
  20. ;*                                                                     *
  21. ;***********************************************************************
  22.  
  23. ;***********************************************************************
  24. ;*                                                                     *
  25. ;* Structure of HOST.HDR for each message in the HOST.MSG file         *
  26. ;*                                                                     *
  27. ;* integer   2 bytes message number                                    *
  28. ;* long      4 bytes offset            - offset into the HOST.MSG file *
  29. ;* integer   2 bytes message length    - length of message in HOST.MSG *
  30. ;* char      1 bytes flag              - see below                     *
  31. ;* string   31 bytes destination       - TO:                           *
  32. ;* string   31 bytes from              - FROM:                         *
  33. ;* string   37 bytes subject           - SUBJECT:                      *
  34. ;* string    9 bytes date              - date message was created      *
  35. ;* string   11 bytes time              - time message was created      *
  36. ;*                                                                     *
  37. ;*  The mail flag is set by adding the desired attributes together.    *
  38. ;*       PUBLIC     0         - anyone can read                        *
  39. ;*       PRIVATE    1         - only TO: and FROM: can read or delete  *
  40. ;*       NEWMAIL    2         - hasn't been read                       *
  41. ;*       DELETED    4         - marked for deletion                    *
  42. ;*                                                                     *
  43. ;* All strings include a NULL at the last position.                    *
  44. ;*                                                                     *
  45. ;***********************************************************************
  46.  
  47. ;***********************************************************************
  48. ;*                                                                     *   
  49. ;* LEAVEMAIL                                                           *
  50. ;*                                                                     *
  51. ;* This procedure creates the mail messages                            *
  52. ;*                                                                     *
  53. ;*                                                                     * 
  54. ;* Calls: HOSTPUTS, HOSTGETS, HOSTGETYN, HOSTGETC, SETFAILURE,         *
  55. ;*        HOSTMSGBOX,   EXITHOST,     MAILGETLINE,  COUNTMSG           *
  56. ;*                                                                     *
  57. ;* Modifies globals: tempfile, name, msgfile, hdrfile                  *
  58. ;*                                                                     *
  59. ;* Labels : GETMESSAGE, LOOP                                           *
  60. ;*                                                                     *
  61. ;***********************************************************************
  62. proc LeaveMail
  63. intparm replyflag
  64. strparm subject
  65. strparm destination
  66. string line, line_num, choice
  67. integer mailflag, line_count, msg_num, chars_to_read, blocksize
  68. integer dummy, length, count
  69. long msgfile_offset, msg_length
  70.  
  71.    fetch aspect scriptpath tempfile
  72.    addfilename tempfile "~HOST.TMP"
  73.    if isfile tempfile
  74.       delfile tempfile
  75.    endif
  76.     
  77.    while 1
  78.       line_count=1
  79.       if ! replyflag
  80.          HostPutS("`r`n`r`n  To: ")
  81.          HostGetS(&destination 30 DISP)
  82.          strupr destination
  83.       endif
  84.  
  85.       if ! replyflag
  86.          HostPutS("`r`nSubj: ")
  87.          HostGetS(&subject 40 DISP)
  88.       endif
  89.  
  90.       HostPutS("`r`n`r`n")
  91.         
  92.       HostPutS("Private Mail (Y/N)? ")
  93.       HostGetYN()
  94.       if success
  95.          mailflag=PRIVATE+NEWMAIL
  96.       else
  97.          mailflag=PUBLIC+NEWMAIL
  98.       endif
  99.         
  100.       HostPutS("`r`n`r`n  To: ")
  101.       HostPutS(destination)
  102.       HostPuts("`r`nFrom: ")
  103.       HostPutS(name)
  104.       HostPutS("`r`nSubj: ")
  105.       HostPutS(subject)
  106.       if ! replyflag
  107.          HostPutS("`r`n`r`nIs this correct (Y/N/Q)? ")
  108.          HostGetC(&choice)
  109.          if not success
  110.             SetFailure()
  111.             return
  112.          endif
  113.          HostPutS(choice)
  114.          HostPutS("`r`n")
  115.          strupr choice
  116.          switch choice
  117.             case "Y"
  118.             endcase
  119.             case "N"
  120.                loopwhile
  121.             endcase
  122.             case "Q"
  123.                return
  124.             endcase
  125.          endswitch
  126.       endif
  127.       fopen 1 tempfile CREATE
  128.       if not success
  129.          HostMsgBox("ERROR - Can't open TEMP file!")
  130.          ExitHost()
  131.       endif
  132.  
  133. GETMESSAGE:
  134.       while 1
  135.          strfmt line_num "%5d: " line_count
  136.          HostPutS("`r`n")
  137.          HostPutS(line_num)
  138.          MailGetLine(&line)
  139.          if not success
  140.             SetFailure()
  141.             return
  142.          endif
  143.          strcmp line ""
  144.          if success
  145.             exitwhile
  146.          endif
  147.          fputs 1 line        ; write line to tempfile
  148.          fputc 1 0x0D        ; append CR to line
  149.          fputc 1 0x0A        ; append LF to line
  150.          line_count++
  151.       endwhile
  152.  
  153. LOOP:
  154.       HostPutS("`r`n`r`nS)ave A)bort D)isplay C)ontinue ? ")
  155.       HostGetC(&choice)
  156.       if not success
  157.          SetFailure()
  158.          return
  159.       endif
  160.       strupr choice
  161.       HostPutS(choice)
  162.       if success
  163.          HostPutS("`r`n")
  164.          strupr choice
  165.          switch choice
  166.             case "S"
  167.                HostPuts("`r`nSaving message ...`r`n")
  168.                isfile msgfile
  169.                if success
  170.                   fopen 0 msgfile WRITE
  171.                   if not success
  172.                      HostMsgBox("ERROR - Can't open HOST.MSG file!")
  173.                      ExitHost()
  174.                   endif
  175.                else
  176.                   fopen 0 msgfile CREATE
  177.                endif
  178.                fseek 0 0 2
  179.                ftell 0 msgfile_offset
  180.                         
  181.                fclose 1
  182.                findfirst tempfile
  183.                msg_length=$FSIZE
  184.                fopen 1 tempfile READWRITE
  185.                length=msg_length
  186.                chars_to_read = msg_length
  187.  
  188.                fseek 0 0 2
  189.                while chars_to_read > 0
  190.                   if chars_to_read > 128
  191.                      blocksize = 128
  192.                   else
  193.                      blocksize = chars_to_read
  194.                   endif
  195.  
  196.                   fread 1 line blocksize dummy
  197.                   fwrite 0 line blocksize
  198.                   if not success
  199.                      HostMsgBox("ERROR - Can't write to HOST.MSG file!")
  200.                      ExitHost()
  201.                   endif
  202.                   chars_to_read = chars_to_read - blocksize
  203.                endwhile
  204.                fclose 0
  205.                fclose 1
  206.                delfile tempfile
  207.                     
  208.                ;count messages to get this message number
  209.                CountMsg(&msg_num)
  210.  
  211.                ;write header info
  212.                isfile hdrfile
  213.                if success
  214.                   fopen 2 hdrfile WRITE
  215.                   if not success
  216.                      HostMsgBox("ERROR - Can't open HOST.MSG file!")
  217.                      ExitHost()
  218.                   endif
  219.                else
  220.                   fopen 2 hdrfile create
  221.                endif
  222.  
  223.                fseek 2 0 2
  224.                CountMsg(&msg_num)
  225.                inc msg_num
  226.                fputi 2 msg_num
  227.                fputl 2 msgfile_offset
  228.                fputi 2 length
  229.                fputc 2 mailflag
  230.                fwrite 2 destination 31
  231.                fwrite 2 name 31
  232.                fwrite 2 subject 37
  233.                fwrite 2 $DATE 9
  234.                fwrite 2 $TIME 11
  235.                fclose 2
  236.             endcase
  237.                 
  238.             case "A"
  239.                HostPutS("`r`nAbort message (Y/N)? ")
  240.                HostGetYN()
  241.                if success
  242.                   fclose 1
  243.                   delfile tempfile
  244.                   return
  245.                endif
  246.                HostPutS("`r`n")
  247.                goto LOOP
  248.             endcase
  249.                 
  250.             case "D"
  251.                count=1
  252.                rewind 1
  253.                while 1
  254.                   fgets 1 line
  255.                   if FEOF 1
  256.                      exitwhile
  257.                   endif
  258.                   HostPutS(line)
  259.                   inc count
  260.                   if count==23
  261.                      count=1
  262.                      HostPuts("-MORE-")
  263.                      HostGetC(&choice)
  264.                      HostPutS("`b`b`b`b`b`b")
  265.                      strupr choice
  266.                      strcmp choice "N"
  267.                      if success
  268.                            exitwhile
  269.                      endif
  270.                   endif
  271.                endwhile
  272.                goto LOOP
  273.             endcase
  274.                 
  275.             case "C"
  276.                goto GETMESSAGE
  277.             endcase
  278.          
  279.             default
  280.                goto LOOP
  281.             endcase
  282.          endswitch
  283.       else
  284.          SetFailure()
  285.       endif
  286.       return
  287.    endwhile
  288. endproc
  289.  
  290. ;***********************************************************************
  291. ;*                                                                     *   
  292. ;* READMAIL                                                            *
  293. ;*                                                                     *
  294. ;* This procedure reads and displays mail messages                     *
  295. ;*                                                                     * 
  296. ;* Calls: COUNTMSG, HOSTPUTS, HOSTGETC, SETFAILURE, HOSTGETS, READMSG  *
  297. ;*                                                                     *
  298. ;* Modifies globals: msg, msg_number                                   *
  299. ;*                                                                     *
  300. ;* Labels : LOOP                                                       *
  301. ;*                                                                     *
  302. ;***********************************************************************
  303. proc ReadMail
  304. string choice
  305. integer msg_total,  searchflag
  306.  
  307. LOOP:
  308.    CountMsg(&msg_total)
  309.    strfmt msg "`r`n`r`nTotal messages: %d`r`n`r`n" msg_total
  310.    HostPutS(msg)
  311.    HostPutS("F)orward read`r`n")
  312.    HostPutS("N)ew mail`r`n")
  313.    HostPutS("S)earch mail`r`n")
  314.    HostPutS("Q)uit`r`n`r`n? ")
  315.    HostGetC(&choice)
  316.    if not success
  317.       SetFailure()
  318.       return
  319.    endif
  320.    HostPuts(choice)
  321.    HostPuts("`r`n")
  322.    strupr choice
  323.    switch choice
  324.       case "F"
  325.          HostPuts("`r`nStarting message number (<CR> for first): ")
  326.          HostGetS(&choice 5 DISP)
  327.          if not success
  328.             SetFailure()
  329.             return
  330.          endif
  331.          HostPuts("`r`n")
  332.          strcmp choice ""
  333.          if success
  334.             msg_number=1
  335.          else
  336.             atoi choice msg_number
  337.             if msg_number>msg_total
  338.                HostPutS("`r`nInvalid msg number!`r`n")
  339.                goto LOOP
  340.             endif
  341.          endif
  342.          while msg_number<=msg_total
  343.             ReadMsg(0)
  344.             if not success
  345.                SetFailure()
  346.                exitwhile
  347.             endif
  348.          endwhile
  349.          HostPutS("`r`nEnd of messages.`r`n")
  350.          goto LOOP
  351.       endcase
  352.  
  353.       case "N"
  354.          msg_number=1
  355.          while msg_number<=msg_total
  356.             ReadMsg(1)
  357.             if not success
  358.                SetFailure()
  359.                exitwhile
  360.             endif
  361.          endwhile
  362.          HostPutS("`r`nEnd of messages.`r`n")
  363.          goto LOOP
  364.       endcase
  365.  
  366.       case "S"
  367.          HostPutS("`r`n`r`nWhich field:  T)o  F)rom  or  S)ubject ? ")
  368.          HostGetS(&choice 1 DISP)
  369.          if not success
  370.             SetFailure()
  371.             return
  372.          endif
  373.          HostPuts("`r`n")
  374.          strupr choice
  375.          switch choice
  376.             case "T"
  377.                searchflag=2
  378.             endcase
  379.             case "F"
  380.                searchflag=3
  381.             endcase
  382.             case "S"
  383.                searchflag=4
  384.             endcase
  385.  
  386.             default
  387.                return
  388.             endcase
  389.          endswitch
  390.          HostPuts("Search string: ")
  391.          HostGetS(&searchstr 30 DISP)
  392.          HostPutS("`r`n")
  393.          if not success
  394.             SetFailure()
  395.             return
  396.          endif
  397.          msg_number=1
  398.          while msg_number<=msg_total
  399.             ReadMsg(searchflag)
  400.             if not success
  401.                SetFailure()
  402.                return
  403.                exitwhile
  404.             endif
  405.          endwhile
  406.          HostPutS("`r`nEnd of messages.`r`n")
  407.          goto LOOP
  408.  
  409.       endcase
  410.  
  411.       case "Q"
  412.          return
  413.       endcase
  414.  
  415.       default
  416.          goto LOOP
  417.       endcase
  418.    endswitch
  419. endproc
  420.  
  421. ;***********************************************************************
  422. ;*                                                                     *   
  423. ;* READMSG                                                             *
  424. ;*                                                                     *
  425. ;* This procedure opens and displays a mail message.                   *
  426. ;*                                                                     *
  427. ;* Calls: HOSTPUTS, HOSTMSGBOX, EXITHOST, CHANGEFLAG, DISPLAYFILE,     *
  428. ;*        HOSTGETC, SETFAILURE, LEAVEMAIL, DELETEMSG                   *
  429. ;*                                                                     *
  430. ;* Modifies globals: tempfile, hdrfile, msg_number, _date, _time,      *
  431. ;*                   access_level, name, msg, msgfile                  *
  432. ;*                                                                     *
  433. ;* Labels: LOOP                                                        *
  434. ;*                                                                     *
  435. ;***********************************************************************
  436. proc ReadMsg
  437. intparm readflag
  438. integer msg_num, msg_length, msg_flag, dummy, chars_to_read, blocksize
  439. long offset, hdr_offset
  440. string destination, from, subject,flag, line, choice, reply="REPLY - "
  441.  
  442.    fetch aspect scriptpath tempfile
  443.    addfilename tempfile "~HOST.TMP"
  444.  
  445.    isfile hdrfile
  446.    if not success
  447.       HostPutS("`r`nNo mail file found!`r`n")
  448.       return
  449.    endif
  450.  
  451.    fopen 0 hdrfile READWRITE
  452.    if not success
  453.       HostMsgBox("ERROR - Can't open HOST.HDR!")
  454.       ExitHost()
  455.    endif
  456.  
  457.    hdr_offset=(msg_number-1)*128       ; goto a specific record in .HDR file
  458.    fseek 0 hdr_offset 0
  459. LOOP:
  460.  
  461.    fgeti 0 msg_num
  462.    if FEOF 0
  463.       SetFailure()
  464.       inc msg_number
  465.       return
  466.    endif
  467.    fgetl 0 offset
  468.    fgeti 0 msg_length
  469.    fgetc 0 msg_flag
  470.    if (msg_flag & 1) ==1
  471.       flag="Private"              ;remove new mail flag
  472.    else
  473.       flag="Public"
  474.    endif
  475.    fread 0 destination 31 dummy
  476.    fread 0 from 31 dummy
  477.    fread 0 subject 37 dummy
  478.    fread 0 _date 9 dummy
  479.    fread 0 _time 11 dummy
  480.  
  481.    if (msg_flag & 1)==1                      ; if message is PRIVATE
  482.       strcmp access_level "2"
  483.       if not success
  484.          strcmp name destination         ; compare user name to TO:
  485.          if not success
  486.             strcmp name from            ; compare user name to FROM:
  487.             if not success
  488.                inc msg_number
  489.                goto LOOP
  490.             endif
  491.          endif
  492.       endif
  493.    endif
  494.  
  495.    if (msg_flag & 4)==DELETED
  496.       inc msg_number
  497.       goto LOOP
  498.    endif
  499.  
  500.    switch readflag
  501.       case 1        ; read new mail only
  502.          strcmp destination name
  503.          if not success
  504.             inc msg_number
  505.             goto loop
  506.          endif
  507.          if (msg_flag & 2)!=NEWMAIL
  508.             inc msg_number
  509.             goto LOOP
  510.          endif
  511.       endcase
  512.  
  513.       case 2         ; search for TO:
  514.          if not strfind destination searchstr
  515.             inc msg_number
  516.             goto LOOP
  517.          endif
  518.       endcase
  519.  
  520.       case 3         ; search for FROM:
  521.          if not strfind from searchstr
  522.             inc msg_number
  523.             goto LOOP
  524.          endif
  525.       endcase
  526.  
  527.       case 4         ; search for SUBJECT
  528.          if not strfind subject searchstr
  529.             inc msg_number
  530.             goto LOOP
  531.          endif
  532.       endcase
  533.  
  534.    endswitch
  535.    fclose 0
  536.  
  537.    strcmp destination name
  538.    if success
  539.       msg_flag=msg_flag & 1               ;unset NEWMAIL flag
  540.       ChangeFlag(msg_flag)
  541.    endif
  542.  
  543.    strfmt msg "`r`n Msg: %d  (%s, sent %s at %s)`r`n" msg_num flag _date _time
  544.    HostPutS(msg)
  545.    strfmt msg "From: %s`r`n" from
  546.    HostPuts(msg)
  547.    strfmt msg "  To: %s`r`n" destination
  548.    HostPutS(msg)
  549.    strfmt msg "Subj: %s`r`n`r`n" subject
  550.    HostPutS(msg)
  551.  
  552.    isfile msgfile
  553.    if not success
  554.       HostMsgBox("No message file!")
  555.       HostPuts("`r`nNo message file!`r`n")
  556.       SetFailure()
  557.       return
  558.    else
  559.       fopen 1 msgfile READ text
  560.       if not success
  561.          HostMsgBox("Can't open message file!")
  562.          HostPutS("`r`nCan't open message file!`r`n")
  563.          SetFailure()
  564.          return
  565.       endif
  566.       fopen 2 tempfile create text
  567.       if not success
  568.          HostMsgBox("Can't open temp file!")
  569.          HostPutS("`r`nCan't open TEMP file!`r`n")
  570.          SetFailure()
  571.          return
  572.       endif
  573.  
  574.       fseek 1 offset 1
  575.  
  576.       chars_to_read = msg_length
  577.       while chars_to_read > 0
  578.          if chars_to_read > 128
  579.             blocksize = 128
  580.          else
  581.             blockSize = chars_to_read
  582.          endif
  583.          fread 1 line blocksize dummy
  584.          fwrite 2 line blocksize
  585.          if not success
  586.             HostMsgBox("Can't write to temp file!")
  587.             ExitHost()
  588.          endif
  589.          chars_to_read = chars_to_read - blocksize
  590.       endwhile
  591.  
  592.       fclose 1
  593.       fclose 2
  594.       DisplayFile(tempfile, 17)
  595.       delfile tempfile
  596.         
  597.       HostPutS("`r`nR)eply  D)elete  Q)uit  (<CR> for another): ")
  598.       HostGetC(&choice)
  599.       if not success
  600.          SetFailure()
  601.          return
  602.       endif
  603.       HostPutS(choice)
  604.       HostPutS("`r`n")
  605.       switch choice
  606.          case "R"
  607.             substr msg subject 0 21
  608.             strcat reply msg
  609.             LeaveMail(1, reply, from)
  610.             if not success
  611.                SetFailure()
  612.                return
  613.             endif
  614.             inc msg_number
  615.             return
  616.          endcase
  617.          case "D"
  618.             DeleteMsg()
  619.          endcase
  620.          case "Q"
  621.             SetFailure()
  622.             return
  623.          endcase
  624.          case "`r"
  625.             inc msg_number
  626.             return
  627.          endcase
  628.          default
  629.             choice=""
  630.          endcase
  631.       endswitch
  632.    endif
  633. endproc
  634. ;**** End of MAIL.WAS ****
  635.